package me.send.business.base;

import java.util.ArrayList;
import java.util.UUID;

import com.esms.MessageData;
import com.esms.PostMsg;
import com.esms.common.entity.Account;
import com.esms.common.entity.GsmsResponse;
import com.esms.common.entity.MTPack;

public class BaseSMS {
	
	/** 调用短信接口 2015年5月27日17:14:46 * */
	public static void getMessage(String telephone, String code) {
		Account ac = new Account("njcbkd@njcbkd", "XW400xw!");// 设置帐号密码
		PostMsg pm = new PostMsg(); // 新建一个PostMsg对象

		pm.getCmHost().setHost("211.147.239.62", 8450);// 您设置的下行端口
		pm.getWsHost().setHost("211.147.239.62", 8460);// 您设置的下行端口

		MTPack pack = new MTPack();
		pack.setBatchID(UUID.randomUUID());
		pack.setBatchName("JDK");
		pack.setMsgType(MTPack.MsgType.SMS);
		pack.setSendType(MTPack.SendType.MASS);
		pack.setBizType(0);
		pack.setDistinctFlag(false);
		pack.setCustomNum("");// 添加扩展码

		ArrayList<MessageData> msgs = new ArrayList<MessageData>();

		// /* 以下是单发实例*/
		msgs.add(new MessageData(telephone, "呼送验证码：" + code + "。（3分钟有效）呼送，助您生活更轻松"));

		pack.setMsgs(msgs);
		try {
			GsmsResponse response = pm.post(ac, pack);
			String message = response.getMessage();
			int result = response.getResult();
			System.out.println(message+":"+result);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
